/*
 * @Author: january.cjy
 * @Date: 2021-09-27 20:19:17
 * @Last Modified by: january.cjy
 * @Last Modified time: 2021-11-02 19:37:00
 */
/*
 * @Author: january.cjy
 * @Date: 2021-09-27 19:49:52
 * @Last Modified by: january.cjy
 * @Last Modified time: 2021-09-27 19:54:06
 */
#pragma once

#include <CmgASTConsumer.h>
#include <CmgPPCallbacks.h>
#include <CmgFileFeature.h>

#include "clang/AST/AST.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"


namespace cmg {
using namespace clang;
using namespace llvm;

class CmgASTFrontendAction : public ASTFrontendAction {
public:
  virtual bool BeginSourceFileAction(CompilerInstance &ci) {
    ci.getPreprocessor().addPPCallbacks(std::unique_ptr<clang::PPCallbacks>(
        new CmgPPCallbacks(ci.getSourceManager(),fileFeature)));
    return true;
  }

  virtual std::unique_ptr<clang::ASTConsumer>
  CreateASTConsumer(CompilerInstance &Compiler, StringRef InFile) {
    return std::unique_ptr<clang::ASTConsumer>(new CmgASTConsumer(
        Compiler.getASTContext(), Compiler.getSourceManager(),
        Compiler.getPreprocessor(),fileFeature));
  }

  //   ~CmgASTFrontendAction() {}

private:
  FileFeature fileFeature;
};

} // namespace cmg